<template>
	<view class="recordBox">
		<view class="top">
			<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text"
				activeColor="#0080fe" style="border-bottom: none;"></uni-segmented-control>
		</view>

		<view class="content">
			<view class="untreated" v-for="(item,index) in list" v-show="current === 0 && item.state == 1 ">
				<view class="untreatedBox">
					<view class="untreatedBox-top" @click="getRepairs(item.id)">
						<view class="top-title">
							{{item.content}}
						</view>
						<view class="top-img">
							<image v-for="(items,i) in item.images" :src="IMGBASEURL+items.url" mode="aspectFill">
							</image>
						</view>
						<view class="top-text">
							<text>{{item.address}}</text>
							<text>{{item.typename}}</text>
						</view>
					</view>
					<view class="untreatedBox-bottom">
						<text>{{item.addtime | timeFormat}}</text>
						<view class="untreatedBox-btn">
							<view class="btn-untreated">
								{{item.statename}}
							</view>
							<view class="btn-revocation" @click="del(item.id)">
								撤销
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="untreated" v-for="(item,index) in list" v-show="current === 1 && item.state == 3 ">
				<view class="untreatedBox">
					<view class="untreatedBox-top" @click="getRepairs(item.id)">
						<view class="top-title">
							{{item.content}}
						</view>
						<view class="top-img">
							<image v-for="(items,i) in item.images" :src="IMGBASEURL+items.url" mode="aspectFill">
							</image>
						</view>
						<view class="top-text">
							<text>{{item.address}}</text>
							<text>{{item.typename}}</text>
						</view>
					</view>
					<view class="untreatedBox-bottom">
						<text>{{item.addtime | timeFormat}}</text>
						<view class="untreatedBox-btn">
							<view class="btn-untreated">
								{{item.statename}}
							</view>
							<view class="btn-revocation" @click="del(item.id)">
								撤销
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="untreated" v-for="(item,index) in list" v-show="current === 2">
				<view class="untreatedBox">
					<view class="untreatedBox-top" @click="getRepairs(item.id)">
						<view class="top-title">
							{{item.content}}
						</view>
						<view class="top-img">
							<image v-for="(items,i) in item.images" :src="IMGBASEURL+items.url" mode="aspectFill">
							</image>
						</view>
						<view class="top-text">
							<text>{{item.address}}</text>
							<text>{{item.typename}}</text>
						</view>
					</view>
					<view class="untreatedBox-bottom">
						<text>{{item.addtime | timeFormat}}</text>
						<view class="untreatedBox-btn">
							<view class="btn-untreated">
								{{item.statename}}
							</view>
							<view class="btn-revocation" @click="del(item.id)">
								撤销
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="noData" v-if="noData">
				没有更多数据了。。。
			</view>
		</view>
	</view>
</template>

<script>
	import {
		repairsList,

		repairState,
		repairsDel,
	} from '../../api/repairs.js'
	import {
		IMGBASEURL,
		IMGBASEURLS,
	} from '../../utils/config.js'
	import moment from 'moment'
	export default {
		data() {
			return {
				items: ['未处理', '已处理', '全部'],
				current: 0,
				IMGBASEURL: IMGBASEURLS,
				list: [],
				total: 0,
				noData: false,
				params: {
					key: '',
					address: '',
					tel: '',
					begindate: '',
					enddate: '',
					state: null,
					type: null,
					page: 1,
					psize: 6
				}
			};
		},
		onLoad() {
			this.repairsList()
		},
		//上拉
		onReachBottom() {
			this.params.page++
			this.repairsList()
		},
		//下拉
		onPullDownRefresh() {
			this.params.page = 1
			this.list = []
			uni.showNavigationBarLoading()
			this.repairsList()
		},
		filters: {
			timeFormat(val) {
				return moment(val).format("YYYY-MM-DD HH:mm")
			}
		},

		methods: {
			//列表
			async repairsList() {
				uni.showLoading({
					title: '加载中'
				})
				let data = await repairsList(this.params)
				if (data.errCode == 10000) {
					uni.hideLoading()
					uni.hideNavigationBarLoading()
					uni.stopPullDownRefresh()
					if (data.data.list == 0) {
						this.noData = true
					}
					let newData = this.list.concat(data.data.list)
					this.list = newData
					this.total = data.data.counts
				}
			},
			//删除
			async del(id) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '是否撤销这条数据',
					success: async function(res) {
						if (res.confirm) {
							let data = await repairsDel({
								id: id
							})
							if (data.errCode == 10000) {
								uni.showToast({
									title: '撤销成功',
									duration: 2000,
									icon: 'success'
								})
							}

						} else if (res.cancel) {
							console.log('用户点击取消');
						}
						location.reload()
						that.questionsList()
					}
				});
			},
			//往详情页面传id
			getRepairs(id) {
				uni.navigateTo({
					url: './details?id=' + id
				})
			},
			
			
			// 切换
			onClickItem(e) {
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;
				}
			}
		},

	}
</script>
<style lang="less" scoped>
	@import '../../static/style/repairsRecord.less';
</style>
